package com.study.gupao.proxy.gpproxy;

import com.study.gupao.proxy.Person;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @ClassName: ProxyMatchmaker
 * @Description: 代理媒人
 * @author: Adminstrator
 * @Date: 2019-03-12 22:15
 */
public class ProxyMatchmaker implements GPInvocationHandler{

    private Person target;
    public Object getInstance(Person person) throws Exception{
        this.target = person;
        Class<?> clazz = target.getClass();
        return GPProxy.newProxyInstance(new GPClassLoader(),clazz.getInterfaces(),this);
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        before();
        Object ob = method.invoke(this.target,args);
        after();
        return ob;
    }

    private void before(){
        System.out.println("我是媒人， 我开始物色姑娘");
    }

    private void after(){
        System.out.println("可以，开始约会");
    }
}
